<%@ page language="java" import="java.util.*,ll.sms.pojo.*" pageEncoding="UTF-8"%>
<%@page import="ll.sms.util.*"%>
<%@page import="ll.sms.web.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
SmsAdmin smsadmin = (SmsAdmin)session.getAttribute("user");


String defaultChannelId = SmsUtil.sessionHelper(session,AdminProperty.adefaultchannel);
List<ChannelCombox> list1 = SmsUtil.getChannelList(defaultChannelId);
System.out.print(list1);
String defaultChannelName = SmsAppContainer.getChannelPool().get(defaultChannelId).getHname()+"(默认)";
 %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>系统管理</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
		<link rel="stylesheet" type="text/css" href="../ext/ext-all.css" />
		<script type="text/javascript" src="../ext/ext-base.js"></script>
		<script type="text/javascript" src="../ext/ext-all.js"></script>
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<script type="text/javascript">
Ext.BLANK_IMAGE_URL = '../images/s.gif';
</script>
<script type="text/javascript">

Ext.onReady(function(){


	var store2 = new Ext.data.SimpleStore({
	fields: ['clazz', 'showname'],
	data : <%=ExtJsonBuilder.channel2ArrayStringNoAll(list1)%>
	});


    var comb1 = new Ext.form.ComboBox({
            emptyText : '<%=defaultChannelName%>',
            store: store2,
            mode:'local',
            readOnly : true,
            triggerAction:'all',
            valueField: 'clazz',
            name:'uchannel_',
            id:'uchannel_',
            hiddenName : 'uchannel',
            displayField:'showname',
 			fieldLabel: '使用默认通道'
 			//withd :140
            });



    var win;
    var win_suggest;
    var win_channel;
    var button = Ext.get('show-btn');
    var button_showsuggest = Ext.get('show-suggest');
	var button_showchannel =  Ext.get('show-channel');

	var form  = new Ext.form.FormPanel({
	lableAlign:'right',
	url:'../ajaxjsp/system.jsp?flag=changepassword',
	lablewidth:'50',
	frame:true,
	defaultType:'textfield',
	items:[{
		fieldLabel:'新密码',
		name:'npwd',
		vtype:'alphanum',
        vtypeText:'密码只能包括字母或者数字',
        inputType : 'password'
	},{
		fieldLabel:'重新输入新密码',
		name:'renpwd',
		vtype:'alphanum',
        vtypeText:'密码只能包括字母或者数字',
        inputType : 'password'
	}
	]
	});
    button.on('click', function(){
        if(!win){
            win = new Ext.Window({
                applyTo     : 'changepassword',
                layout      : 'fit',
                width       : 300,
                height      : 150,
                closeAction :'hide',
                plain       : true,
                items       : [form],

                buttons: [{
                    text     : '提交',
                    handler  : function(){
                    form.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						 Ext.Msg.alert('成功',action.result.msg);
						 win.hide();
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);
							}else{
							Ext.MessageBox.alert('错误','操作失败');
							}
					}
				});

                    }

                },{
                    text     : '关闭',
                    handler  : function(){
                        win.hide();
                    }
                }]
            });
        }
        win.show(button);
    });
//end win

	var channelform  = new Ext.form.FormPanel({
	lableAlign:'right',
	url:'../ajaxjsp/system.jsp?flag=changechannel',
	lablewidth:'50',
	frame:true,
	defaultType:'textfield',
	items:[comb1]
	});

    button.on('click', function(){
        if(!win){
            win = new Ext.Window({
                applyTo     : 'changepassword',
                layout      : 'fit',
                width       : 300,
                height      : 150,
                closeAction :'hide',
                plain       : true,
                items       : [form],

                buttons: [{
                    text     : '提交',
                    handler  : function(){
                    form.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						 Ext.Msg.alert('成功',action.result.msg);
						 win.hide();
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);
							}else{
							Ext.MessageBox.alert('错误','操作失败');
							}
					}
				});

                    }

                },{
                    text     : '关闭',
                    handler  : function(){
                        win.hide();
                    }
                }]
            });
        }
        win.show(button);
    });

//suggest begin
	var SuggestRecord = Ext.data.Record.create([
	    {name: 'sid', type: 'string'},
        {name: 'suname', type: 'string'},
        {name: 'stype', type: 'string'},
        {name: 'scontent', type: 'string'},
        {name: 'saddtime', type: 'string'}

    ]);

 var store = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({url: '../ajaxjsp/system.jsp?flag=suggest'}),
        reader: new Ext.data.JsonReader({
        totalProperty: 'totalCount',
        root: 'result'
        },SuggestRecord),
        remoteSort: true
    });

   var sm = new Ext.grid.CheckboxSelectionModel();
   sm.handleMouseDown = Ext.emptyFn;

    var columns = new Ext.grid.ColumnModel([
        new Ext.grid.RowNumberer(),
        sm,
        {header: '反馈者', dataIndex: 'suname'},
        {header: '类型', dataIndex: 'stype'},
        {header: '内容', dataIndex: 'scontent'},
        {header: '添加时间', dataIndex: 'saddtime'}
    ]);

       columns.defaultSortable = true;

        var grid = new Ext.grid.EditorGridPanel({
        title: '意见和建议列表',
        loadMask: true,
        store: store,
        cm: columns,
        height : 400,
        margins: '2 2 2 2',
        columnWidth : .5,
        sm: sm,
        viewConfig: {
        columnsText:'显示的列',
        sortAscText:'升序',
        sortDescText:'降序',
        forceFit: true
        },
        bbar: new Ext.PagingToolbar({
            pageSize: 15,
            store: store,
            displayInfo: true,
            displayMsg: '显示 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg:'没有记录'

        }),
        tbar: new Ext.Toolbar({
        items:[
               {
                    id:'del'
                    ,text:"删除"
                    ,handler: function(){
                    doGrid();
                    }
                }

            ]
        })
    });

    store.load({params:{start:0,limit:15}});

	var doGrid =function (){

        var rows = grid.getSelectionModel().getSelections();
        if (rows.length == 0) {
            Ext.MessageBox.alert('警告', '最少选择一条信息，进行操作!');
        }
        else {
            Ext.MessageBox.confirm('提示框', '您确定要进行该操作？', function(btn){
                if (btn == 'yes') {
                var delid='';
                    for (var i = 0; i < rows.length; i++) {
                        delid=delid+rows[i].get('sid')+'^';
                    }

                 Ext.Ajax.request({
                  url : '../ajaxjsp/system.jsp?flag=suggestdel',
                  method : 'POST',
                  params : {
                      //delid : delid
                      delid : '123'
                  },
                  success: function(response, options) {
                        //获取响应的json字符串
                       var responseArray = Ext.util.JSON.decode(response.responseText);
                            if(responseArray.success==true){
								grid.getStore().reload({params:{start:0,limit:15}});

                            }
                            else{
                                Ext.Msg.alert('失败','删除操作失败');
                            }
                         }
              });
                }
            });
        }
    }
//end grid

button_showsuggest.on('click', function(){

        if(!win_suggest){
            win_suggest = new Ext.Window({
                applyTo     : 'show-suggest-div',
                layout      : 'fit',
                width       : 500,
                height      : 400,
                closeAction :'hide',
                plain       : true,
                items       : [grid],

                 buttons: [
					{
                    text     : '关闭',
                    handler  : function(){ win_suggest.hide();}
                    }
				]
            });
        }
        win_suggest.show(button_showsuggest);
    });

button_showchannel.on('click', function(){

        if(!win_channel){
            win_channel = new Ext.Window({
            	title       : '默认通道修改',
                applyTo     : 'button-showchannel-div',
                layout      : 'fit',
                width       : 400,
                height      : 200,
                closeAction :'hide',
                plain       : true,
                items       : [channelform],

                buttons: [
                {
                    text     : '保存',
                    handler  : function(){
                    channelform.form.submit({
					waitMsg : '正在处理......',
					success : function(form, action) {
						 Ext.Msg.alert('成功',action.result.msg);
						 win_channel.hide();
					},
					failure : function(form, action) {
						if (action.failureType == Ext.form.Action.SERVER_INVALID){
							Ext.MessageBox.alert('错误',action.result.errors.msg);
							}else{
							Ext.MessageBox.alert('错误','操作失败');
							}
					}
				});

                    }

                },
					{
                    text     : '关闭',
                    handler  : function(){ win_channel.hide();}
                    }
				]
            });
        }
        win_channel.show(button_showchannel);
    });

});

</script>
  </head>

  <body>
   <br>
   <hr>
   <input type="button" id="show-btn" value="修改密码" />
   <hr>
   <input type="button" id="show-channel" value="默认通道修改" />
   <%if(smsadmin.getArank()==SmsConstant.ADMIN_TYPE){ %>
   <hr>
   <input type="button" id="show-suggest" value="查询意见或建议" />
   <%}else{
   %>
    <input type="button" id="show-suggest" value="查询意见或建议" style="display : none"/>
   <%} %>
<div id="changepassword" class="x-hidden"></div>
<div id="show-suggest-div" class="x-hidden"></div>
<div id="button-showchannel-div" class="x-hidden"></div>

  </body>
</html>
